<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('新增库存冻结')"/>

<body style="background-color: #f2f2f2;">

<div class="layui-fluid larry-wrapper">
    <input type="hidden" th:value="${id}" id="kid">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">

                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">冻结单号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="djdh" name="djdh" placeholder="冻结单号"
                                   readonly="readonly"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="bz" name="bz" placeholder="备注"/>
                        </div>
                    </div>

                    <div class="moreSearch" style="display: none">
                        <div class="layui-inline">
                            <label class="layui-form-label">货品编号</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input"
                                       id="hpbh" name="hpbh" placeholder="货品编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">货品名称</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input"
                                       id="hpmc" name="hpmc" placeholder="货品名称"/>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">库位名称</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input"
                                       id="kwmc" name="kwmc" placeholder="库位名称"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">货品批次
                            </label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input"
                                       id="hppc" name="hppc" placeholder="货品批次"/>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">生产日期</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="scrq_start" id="scrq_start"
                                       placeholder="yyyy-MM-dd"/>
                            </div>
                        </div>
                        <div class="layui-inline inline-search-btn">
                            <a class="layui-btn layui-btn-normal" data-type="reload">查询</a>
                        </div>
                        <div class="layui-inline inline-reset-btn">
                            <button type="reset" class="layui-btn layui-btn-normal" style="background-color: #40AFFE">
                                重置
                            </button>
                        </div>
                    </div>
                </form>
          <div class="moreBtn"><i class="layui-icon layui-icon-triangle-d" style="color: #1E9FFF;"></i></div>
                <div class="group-button" id="toolbar">
                    <a class="layui-btn layui-btn-sm layui-btn-normal eidtBtn">
                        <i class="layui-icon">&#x1005;</i> 保存并冻结
                    </a>
                </div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table1" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>
</body>
<div th:include="public/public_js::public_js"></div>
<style type="text/css">

</style>
<script>


    $(".moreBtn").on("click", function () {
        $(".moreSearch").toggle();
    })
    var $table;
    var xx_number = 0;
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate'], function () {
        /*window.operateEvent = {

            "click #btn_edit": function (e, value, row, index) {//编辑
                edit(row.id);
            }
        }*/
        //冻结单号回显
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        zzpUtils.action({
            url: "/wmsstockfrozen/searchDjdh",
            data: JSON.stringify(),
            success: function (data) {
                zzpUtils.loadJsonDataToForm(data);
            }, error: function (xhr, textStatus) {
                console.log(textStatus);
                console.log(xhr)
            }
        });

        laydate.render({
            elem: '#scrq_start'
            , theme: '#20a0ff'
            , range: '~'//练起来
        })


        $table = zzpUtils.table({
            elem: '#table1',
            isApi: true,
            uniqueId: "kcid",
            pagination: true,
            url: '/wmsstockfrozen/searchHp',
            columns: [{
                field: '',
                checkbox: true
            }, {
                field: 'idex',
                title: 'idex',
                visible: false
            }, {
                field: 'nuber',
                title: 'nuber',
                visible: false
            }, {
                field: 'hpbh',
                title: '货品编号'
            }, {
                field: 'hpmc',
                title: '货品名称'
            }, {
                field: 'hppc',
                title: '货品批次'
            }, {
                field: 'scrq',
                title: '生产日期',
                formatter: function (value, row, index) {
                    var sj='';
                    if(value!=null&&value!=''){
                        sj=value.substring(0,19);
                    }
                    return sj;
                }
            }, {
                field: 'sxrq',
                title: '失效日期',
                formatter: function (value, row, index) {
                    var sj='';
                    if(value!=null&&value!=''){
                        sj=value.substring(0,19);
                    }
                    return sj;
                }
            }, {
                field: 'zxl',
                title: '装箱量'
            }, {
                field: 'dwms',
                title: '单位描述'
            }, {
                field: 'rksj',
                title: '入库日期',
                formatter: function (value, row, index) {
                    var sj='';
                    if(value!=null||value!=''){
                        sj=value.substring(0,19);
                    }
                    return sj;
                }
            }, {
                field: 'kwmc',
                title: '库位名称'
            }, {
                field: 'kdjsl',
                title: '可冻结数量',
                visible: true
            }, {
                field: 'djsl',
                title: '冻结数量',
                /*formatter: operateFormatterNumber*/
               /* formatter: operateFormatterNumber,*/
                editable: {
                    type: 'text',
                    clear: false,
                    validate: function (value) {
                        if (isNaN(value)) return {newValue: 1, msg: '只允许输入数字'};
                        else if (value <= 0) return {newValue: 1, msg: '不能输入负数或0'};
                        else if (value <= Number(xx_number)) return {newValue: value};
                        else if (value > Number(xx_number)) return {newValue: xx_number};
                    },
                }
            }],
            queryParams: function () {//查询条件
                return zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            onClickRow: function (row, $element, field) {
                xx_number = row.kdjsl;
            },
        });

        /*function operateFormatterNumber(value, row, index) {
            return 1;
        }*/

        /*function operateFormatterNumber (value,row,index) {
            return [
                '<input type="text"  id="dongjieNumber'+index+'" onblur="changett('+index+','+row.kdjsl+',\''+row.kcid+'\')"  value="'+ value +'"/>',
            ].join('')
        }*/
        $(".inline-search-btn").on('click', function () {
            zzpUtils.refreshTable("#table1");
        })
        $(".eidtBtn").on('click', function () {
            var rows = $("#table1").bootstrapTable('getSelections');
            var b=0;
            for (var i = 0; i < rows.length; i++) {
               var a=rows[i].djsl;
               if(a=='0'){
                   b++;
               }
            }
            if (rows.length == 0) {
                layer.msg("请选择一条进行冻结");
            } else if(b>0){
                layer.msg("您选择的数据有冻结数量为0的，不可为0");
            }else {
                var djdh = $("#djdh").val();
                var bz = $("#bz").val();
                zzpUtils.action({
                    url: "/wmsstockfrozen/add",
                    data: JSON.stringify({list: rows, djdh: djdh, bz: bz}),
                    success: function (data) {
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            top.layer.msg(data.title);
                        }, 500);
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                });
            }
        })
    });
    /*function changett(index,sl,id){
       var dongjiedata = $('#dongjieNumber'+index).val();
        if (/^\d+$/.test(dongjiedata)) {
            if (parseInt(dongjiedata) <= parseInt(sl)) {
                $('#dongjieNumber'+index).val(dongjiedata);
            }else{
                $('#dongjieNumber'+index).val(sl);
            }
        }
    }*/

</script>
</html>